<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑权限</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/frame.css">

    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
</head>
<body>           
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>编辑权限</legend>
</fieldset>

<form class="layui-form layui-form-pane" action="" lay-filter="example" style="padding: 20px">
    <input type="hidden" name="id" value="{$menu.id}" lay-verify="id">

    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="text" name="name" value="{$menu.name}" lay-verify="name" autocomplete="off" placeholder="请输入名称" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span style="color: red">*</span> 长度1-30个字符
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">上级菜单</label>
        <div class="layui-input-inline" style="width: 40%">
            <select name="pid">
                {foreach $menu_list as $k => $v}
                {if $menu['pid']== $v['id']}
                <option value="{$v.id}" selected>{$v.name}</option>
                {else /}
                <option value="{$v.id}">{$v.name}</option>
                {/if}
                {/foreach}
            </select>
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span style="color: red">*</span> 一级菜单请留空
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">模块名</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="text" name="module" value="{$menu.module}" lay-verify="module" autocomplete="off" placeholder="请输入模块名" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span style="color: red">*</span> 一级菜单请留空
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">控制器名</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="text" name="controller" value="{$menu.controller}" lay-verify="controller" autocomplete="off" placeholder="请输入控制器名" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span style="color: red">*</span> 一级菜单请留空
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">方法名</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="text" name="action" value="{$menu.action}" lay-verify="action" autocomplete="off" placeholder="请输入方法名" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span style="color: red">*</span> 一级菜单请留空
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">排序值</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="text" name="sort" value="{$menu.sort}" value="1" lay-verify="sort" autocomplete="off" placeholder="请输入排序值" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span style="color: red">*</span> 数字越大越靠前
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">图标</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="text" name="icon" value="{$menu->getData('icon')}" lay-verify="icon" autocomplete="off" placeholder="请输入图标值" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span style="color: red">*</span> 子菜单请留空
            <!-- <a style="cursor:pointer;color:red" onclick="x_admin_show('图标','icon.html',1200,800)">图标（绿色值）</a> -->
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
            <a href="javascript:history.back(-1)" class="layui-btn layui-btn-primary">返回</a>
        </div>
    </div>
</form>
          
<script src="/static/layui/layui.js" charset="utf-8"></script>

<script>
    layui.use(['form', 'layedit'], function(){
        var form = layui.form, layer = layui.layer;

        // 监听提交
        form.on('submit(submit)', function(data){
            // 加载中样式... 
            let loading = layer.msg('正在修改，请稍后...', {icon: 16, shade: 0.3, time:0});

            $.post('{:url("Auth/menu_edit_data")}', data.field, function(res){
                layer.close(loading);
                if(res.code == 0){
                    layer.msg(res.msg, {icon: 1,time: 1500}, function(){
                        // window.location.href = "{:url('Auth/menu_list')}";
                        history.back(-1)
                    });
                }else{
                    layer.msg(res.msg, {icon: 2});
                }
            })

            return false;
        });
    });
</script>
</body>
</html>